package czh.cocoa.foundation;

import java.util.Arrays;

public class NSIndexPath extends NSObject {

	private int[] mIndexes;
	
	public NSIndexPath(int[] indexes) {
		mIndexes = indexes;
	}
	
	public NSIndexPath(int index) {
		mIndexes = new int[]{index};
	}
	
	public int indexAtPosition(int node) {
		return mIndexes[node];
	}
	
	public boolean isEqual(NSObject o) {
		if (o instanceof NSIndexPath) {
			NSIndexPath other = (NSIndexPath) o;
			if (mIndexes.length == other.mIndexes.length) {
				for (int i = 0; i < mIndexes.length; i++) {
					if (mIndexes[i] != other.mIndexes[i]) {
						return false;
					}
				}
				return true;
			}
		}
		return false;
	}
	
	public int hash() {
		int hashcode = 0;
		for (int i = 0; i < mIndexes.length; i++) {
			hashcode += mIndexes[i] * Math.pow(10, i); 
		}
		return hashcode;
	}
	
//UIKit
	
	public static NSIndexPath indexPathForRowInSection(int row, int section) {
		int[] indexes = new int[]{section, row};
		return new NSIndexPath(indexes);
	}
	
	public int row() {
		return indexAtPosition(1);
	}
	
	public int section() {
		return indexAtPosition(0);
	}
	
}
